package com.example.demo.common;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AppConfig implements WebMvcConfigurer {
    //WebMvcConfigurer容器设置拦截规则

    @Autowired
    private  LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {   //这个就是添加拦截规则addInterceptors

        /*List<String> excludes=new ArrayList<>();
        excludes.add("");*/
        List<String> excludes=new ArrayList<String>(){
            {  //两种效果一样
                add("/**/*.html");///**表示任意路径/*表示任意路径下的任意目录
                add("/js/**");
                add("/css/**");
                add("/img/**");
                add("/editor.md/**");
                add("/user/login");
                add("/user/reg");
                add("/art/detail");
                add("/user/myInfo2");
                add("/user/myInfo");
                add("/art/list");
                add("/art/gettotalpage");
                add("/art/gett");
                add("/art/mylist");
                add("/art/writeblog");
            }};
        InterceptorRegistration registration=registry.addInterceptor(loginInterceptor);
        registration.addPathPatterns("/**");//拦截的内容
        registration.excludePathPatterns(excludes);//不拦截的内容
    }
}
